<?php

function smarty_function_load_specific_view($params, &$smarty) {
    $view_file_name = "";
    $module = "";
    if (empty($params['name'])) 
        $smarty->trigger_error("missing 'name' attribute in <strong>load_view</strong> tag", E_USER_ERROR, __FILE__, __LINE__);
    else  $view_file_name = $params['name'].".tpl";

    if(empty($params['module'])){
        $smarty->trigger_error("missing 'module' attribute in <strong>load_view</strong> tag", E_USER_ERROR, __FILE__, __LINE__);
    }else $module = $params['module'];
    
    $theme  = $smarty->get_theme();
    $param_view_folder = isset($params['views_folder']) ? $params['views_folder'] : NULL;
    if($smarty->is_admin_theme()){
        $folder = $param_view_folder===NULL ? "admin_views" : $param_view_folder;
         $view_file_location = "../../$module/$folder/$view_file_name";
    }else{
        if(!$smarty->is_default_theme()){
            $folder = $param_view_folder===NULL ? "views" : $param_view_folder;
            if(file_exists(APPPATH . "$folder/$theme/$module/$view_file_name")){
                $view_file_location = "../../$folder/$theme/$module/$view_file_name";
            }else{
                $view_file_location = "../../modules/$module/$folder/$view_file_name";
            }
        }else{
            $folder = $param_view_folder===NULL ? "views" : $param_view_folder;
            $view_file_location = "../../$module/$folder/$view_file_name";
        }
    }
    $_params = array('smarty_include_tpl_file' =>  $view_file_location, 'smarty_include_vars' => (array)$params);
    $smarty->_smarty_include($_params);

}
?>